<?php
class Task{
	private $nenufish_task_findUser;

	/****************************************************************
     * 查询函数
     * 根据状态查找
     * 1表示任务进行中未完成 
     * 2表示任务完成等待发布方确认 
     * 3表示发布方确认完毕等待发布方完成技能任务 
     * 4表示发布方确认完毕等待发布方付款 
     * 5表示发布方付款完毕或技能任务完成等待完成方确认 
     * 6表示任务结束 
     * 7表示任务状态异常例如被举报
     ****************************************************************/

	/*
     * 查询函数
     * 根据状态查找某用户发布的各状态skillfind
     * 用于用户查询自己发布的skillfind
     */
	public function selectFindByState($nenufish_task_findUser,$nenufish_task_state){
		 $conn = new conn("123.207.114.241:3306","root","root","db_nenufish");
		 $link = $conn->connection();
		 $sql = "SELECT * FROM db_nenufish_task WHERE nenufish_task_state='".$nenufish_task_state."' and nenufish_task_findUser='".$nenufish_task_findUser;
		 $query = mysqli_query($link,$sql) ;
		 return $query;
	}

	/*
     * 查询函数
     * 根据状态查找某用户发布的各状态skilloffer
     * 用于用户查询自己发布的skilloffer
     */
	public function selectOfferByState($nenufish_task_offerUser,$nenufish_task_state){
		 $conn = new conn("123.207.114.241:3306","root","root","db_nenufish");
		 $link = $conn->connection();
		 $sql = "SELECT * FROM db_nenufish_task WHERE nenufish_task_state='".$nenufish_task_state."' and nenufish_task_findUser='".$nenufish_task_offerUser;
		 $query = mysqli_query($link,$sql) ;
		 return $query;
	}

	/*
     * 添加函数
     * 在task表中添加offer任务
     * 用于存被人接取的offer任务
     */
	public function addOfferTask($nenufish_task_skillofferId,$nenufish_task_findUser,$nenufish_task_offerUser){
		 $conn = new conn("123.207.114.241:3306","root","root","db_nenufish");
		 $link = $conn->connection();
		 $sql = "INSERT INTO db_nenufish_task(nenufish_task_skillofferId,nenufish_task_findUser,nenufish_task_offerUser) 
		 		 VALUES('".$nenufish_task_skillofferId."','".$nenufish_task_findUser."','".$nenufish_task_offerUser."')";
		 $query = mysqli_query($link,$sql) ;
		 return $query;
	}

	/*
     * 添加函数
     * 在task表中添加find任务
     * 用于存被人接取的find任务
     */
	public function addFindTask($nenufish_task_skillfindId,$nenufish_task_findUser,$nenufish_task_offerUser){
		 $conn = new conn("123.207.114.241:3306","root","root","db_nenufish");
		 $link = $conn->connection();
		 $sql = "INSERT INTO db_nenufish_task(nenufish_task_skillfindId,nenufish_task_findUser,nenufish_task_offerUser) 
		 		 VALUES('".$nenufish_task_skillfindId."','".$nenufish_task_findUser."','".$nenufish_task_offerUser."')";
		 $query = mysqli_query($link,$sql) ;
		 return $query;
	}

	/*
     * 删除函数
     * 根据ID删除task
     * 用于后台管理删除某任务，或者用户自己删除自己发布的任务
     */
	public function delete($nenufish_task_id){
		 $conn = new conn("123.207.114.241:3306","root","root","db_nenufish");
		 $link = $conn->connection();
		 $sql = "DELETE FROM db_nenufish_task WHERE nenufish_task_id=".$nenufish_task_id;
		 $query = mysqli_query($link,$sql) ;
		 return $query;
	}

	/*
     * 修改函数
     * 根据ID修改状态
     * 用于记录交接过程的状态
     */
	public function updateState($nenufish_task_id,$nenufish_task_state){
		 $conn = new conn("123.207.114.241:3306","root","root","db_nenufish");
		 $link = $conn->connection();
		 $sql = "UPDATE db_nenufish_task SET nenufish_task_state='".$nenufish_task_state."' WHERE nenufish_task_id=".$nenufish_task_id;
		 $query = mysqli_query($link,$sql) ;
		 return $query;
	}
}
?>